package com.cgnpc.scp.common.utils;

import com.cgnpc.scp.manager.mybatis.entity.DataDict;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataDictUtil {
    /**
     * PurchaseProject_exportExcel:调试采购管理-基础数据-项目-导出Excel;
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASEPROJECT_EXPORTEXCEL = "PurchaseProject_exportExcel";

    /**
     * PurchaseContract_exportExcel:调试采购管理-基础数据-合同-导出Excel;
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASECONTRACT_EXPORTEXCEL = "PurchaseContract_exportExcel";

    /**
     * PurchaseContractItem_exportExcel:调试采购管理-基础数据-合同物项服务---导出Excel;
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASECONTRACTITEM_EXPORTEXCEL = "PurchaseContractItem_exportExcel";

    /**
     * PurchaseCapital_exportExcel:调试采购管理-资金计划---导出Excel;
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASECAPITAL_EXPORTEXCEL = "PurchaseCapital_exportExcel";

    /**
     * HseMeetingInfo_exportExcel:调试HSE管理-会议信息---导出Excel;
     */
    public static final String DICT_GROUP_KEY_WITH_HSEMEETINGINFO_EXPORTEXCEL = "HseMeetingInfo_exportExcel";

    /**
     * HseMeetingInfo_meeting_type:HSE会议-会议类型;
     */
    public static final String DICT_GROUP_KEY_WITH_HSEMEETINGINFO_MEETING_TYPE = "HseMeetingInfo_meeting_type";

    /**
     * 调试采购管理-资金计划-类型
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASECAPITAL_TYPE = "PurchaseCapital_type";

    /**
     * 调试采购管理-资金计划-支付公司
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASECAPITAL_PAYMENT_COMPANY = "PurchaseCapital_payment_company";

    /**
     * 调试采购管理-资金计划-币种
     */
    public static final String DICT_GROUP_KEY_WITH_PURCHASECAPITAL_CURRENCY = "PurchaseCapital_currency";

    /**
     * 调试科研创新管理---成果管理----能力建设
     */
    public static final String DICT_GROUP_KEY_WITH_CAPACITY_EXPORTEXCEL = "Capacity_exportExcel";

    //数字字典固定的值==Standard_exportExcel;成果管理----科研课题
    //String exportDictGroupKey = DataDictUtil.DICT_GROUP_KEY_WITH_CAPACITY_EXPORTEXCEL;
    public static final String DICT_GROUP_KEY_WITH_STANDARD_EXPORTEXCEL = "Standard_exportExcel";
    /**
     * 调试科研创新管理---成果管理----科研课题
     */
    public static final String DICT_GROUP_KEY_WITH_SUBJECT_EXPORTEXCEL = "Subject_exportExcel";

    public static Map<String, Map<String, DataDict>> parseDictGroupKeyWithDictKeyWithMap(List<DataDict> dataDictList) {
        Map<String, Map<String, DataDict>> usedDictGroupKeyWithDictKeyWithMap = new HashMap<>();

        if (ListUtil.getListSizeWith0(dataDictList) > 0) {
            String dictGroupKey = null;
            String dictKey = null;

            for (DataDict dataDict : dataDictList) {
                dictGroupKey = dataDict.getDictGroupKey();
                dictKey = dataDict.getDictKey();

                if (!usedDictGroupKeyWithDictKeyWithMap.containsKey(dictGroupKey)) {
                    usedDictGroupKeyWithDictKeyWithMap.put(dictGroupKey, new HashMap<>());
                }

                usedDictGroupKeyWithDictKeyWithMap.get(dictGroupKey).put(dictKey, dataDict);
            }
        }

        return usedDictGroupKeyWithDictKeyWithMap;
    }

    public static DataDict getDataDict(
            Map<String, Map<String, DataDict>> usedDictGroupKeyWithDictKeyWithMap
            , String dictGroupKey
            , String dictKey
    ) {
        if (usedDictGroupKeyWithDictKeyWithMap != null && usedDictGroupKeyWithDictKeyWithMap.size() > 0) {
            Map<String, DataDict> usedDictGroupKeyMap = usedDictGroupKeyWithDictKeyWithMap.get(dictGroupKey);

            if (usedDictGroupKeyMap != null && usedDictGroupKeyMap.size() > 0) {
                DataDict usedDataDict = usedDictGroupKeyMap.get(dictKey);
                return usedDataDict;
            }
        }

        return null;
    }

    public static String getDictText(DataDict dataDict) {
        return dataDict == null ? null : dataDict.getDictText();
    }

}
